from django.http import *
from django.http import HttpResponseRedirect
from tweepy import *
import utils

def auth(request):
    return HttpResponseRedirect(utils.auth_handler.get_authorization_url())

def callback(request):
    token = request.GET['oauth_token']
    access_token = utils.auth_handler.get_access_token(token)
    resp = HttpResponseRedirect('/home')
    resp.set_cookie('oauth', '1')
    resp.set_cookie('oauth_key', access_token.key)
    resp.set_cookie('oauth_secret', access_token.secret)
    resp.set_cookie('user', utils.auth_handler.get_username())
    return resp